var chart;
var qiemian;
var alarm = "35";
var cwmxBak;
var Sjxq = function() {
	var drawQiemian = function(cablehang, cablelie, cableceng, alarmtemp) {
		alarm = alarmtemp;
		var wendu_data = [];
		$.each(qiemian, function(n, value) {
			var obj = new Object();
			obj.x = value.x * 1;
			obj.y = value.y * 1;
			obj.z = value.z * 1;
			obj.lan = value.lan;
			obj.temp = value.temp;
			if (obj.temp * 1 > alarmtemp * 1) {
				obj.color = "yellow";
			} else {
				obj.color = "#87CEEB";
			}
			wendu_data.push(obj);
		});
		chart = new Highcharts.Chart(
			{
				chart : {
					renderTo : 'qiemianChartView',
					margin : 70,
					type : 'scatter',
					// height : 550,
					// width : 1000,
					options3d : {
						enabled : true,
						alpha : 10,
						beta : 15,
						depth : 1500,
						viewDistance : 10,
						frame : {
							bottom : {
								size : 1,
								color : 'rgba(255,150,137,0.3)'
							},
							back : {
								size : 1,
								color : 'rgba(176,226,255,0.1)'
							},
							side : {
								size : 1,
								color : 'rgba(255,250,137,0.2)'
							}
						}
					}
				},
				plotOptions : {
					scatter : {
						dataLabels : {
							enabled : true, // 开启数据标签
							formatter : function() {
								return this.point.temp;
							},
							allowOverlap : true,
						}
					}
				},
				title : {
					text : cwmxBak.storehousecode + "号仓" + ' ~ 测温明细'
				},
				subtitle : {
					text : '单击轴标签可观察切面图'
				},
				xAxis : {
					tickmarkPlacement : 'on',
					min : 0,
					max : cablelie * 1 + 1,
					tickInterval : 1,
					labels : {
						formatter : function() {
							if (this.value == 0 || this.value > cablelie * 1) {
								return "";
							}
							return '<a href="javascript:changeX(\'' + this.value + '\')">第' + (this.value)
								+ '列</a>';
						},
						rotation : 30
					}
				},
				yAxis : {
					tickmarkPlacement : 'on',
					min : 0,
					max : cableceng * 1 + 1,
					reversed : true,
					tickInterval : 1,
					title : null,
					labels : {
						formatter : function() {
							if (this.value == 0 || this.value > cableceng * 1) {
								return "";
							}
							return '<a href="javascript:changeY(\'' + this.value + '\')">第' + (this.value)
								+ '层</a>';
						}
					}
				},
				zAxis : {
					tickmarkPlacement : 'on',
					min : 0,
					max : cablehang * 1 + 1,
					reversed : true,
					tickInterval : 1,
					labels : {
						formatter : function() {
							if (this.value == 0 || this.value > cablehang * 1) {
								return "";
							}
							return '<a href="javascript:changeZ(\'' + this.value + '\')">第' + (this.value)
								+ '行</a>';
						},
						align : 'left',
						x : 100,
					}
				},
				legend : {
					enabled : true,
					layout : 'vertical',
					align : 'right',
					verticalAlign : 'bottom',
					itemMarginTop : 10,
					y : -100,
				},
				series : [ {
					type : "scatter",
					name : "正常温度",
					data : wendu_data
				}, {
					type : "scatter",
					name : "告警温度",
					color : 'yellow'
				}, {
					type : "scatter",
					name : "最低温度",
					color : 'blue'
				}, {
					type : "scatter",
					name : "最高温度",
					color : 'red'
				} ],
				tooltip : {
					formatter : function() {
						return '第' + this.point.z + '行，第' + this.point.x + '列，第' + this.point.y + '层,温度:'
							+ this.point.temp;
					},
					hideDelay : 10,
				},
				credits : {
					text : ""
				}
			});
	}

	var drawSanwen = function(sanwen) {
		var time = [];
		var cangwen = [];
		var waiwen = [];
		var liangwen = [];
		$.each(sanwen, function(n, value) {
			time.push(value.checktime);
			cangwen.push(value.intemp * 1);
			waiwen.push(value.outtemp * 1);
			liangwen.push(value.avgtemp * 1);
		});

		$('#sanwenView').highcharts({
			chart : {
				type : 'spline'
			},
			title : {
				text : sanwen[0].storehousecode + "号仓" + ' ~ 三温图'
			},
			xAxis : {
				type : "datetime",
				data : time,
				gridLineDashStyle : 'ShortDot'
			},
			yAxis : {
				type : 'linear',
				labels : {
					formatter : function() {
						return this.value + '℃';
					}
				}
			},
			tooltip : {
				crosshairs : true,
				shared : true
			},
			plotOptions : {
				spline : {
					marker : {
						radius : 4,
						lineColor : '#666666',
						lineWidth : 1
					},
				}
			},
			credits : {
				text : ""
			},
			series : [ {
				name : '外温',
				marker : {
					fillColor : '#1C1C1C',
					symbol : 'square',
					radius : 2
				},
				lineColor : '#1C1C1C',
				data : waiwen
			}, {
				name : '仓温',
				marker : {
					fillColor : '#00FFFF',
					symbol : 'triangle',
					radius : 2
				},
				lineColor : '#00FFFF',
				data : cangwen
			}, {
				name : '粮温',
				marker : {
					fillColor : '#FF0000',
					symbol : 'circle',
					radius : 2
				},
				lineColor : '#FF0000',
				data : liangwen
			} ]
		});
	}

	var getSanwen = function(id) {
		$.ajax({
			type : "GET",
			cache : false,
			url : "lq/sanwen?orgcode=" + orgcode + "&storehousecode=" + id,
			success : function(responseJson) {
				if (responseJson.success == true) { // 返回true
					var sanwen = responseJson.obj;
					drawSanwen(sanwen);
				} else {
					QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "error");
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				QTYYComponents.bootstrapSweetAlert("", "查询失败!!!", "error");
			}
		});
	}

	var createTable = function(cwmx) {
		if (cwmx.points == null) {
			return;
		}
		$("#cwmxView").empty();
		var $table = $("<table class='cwmxView'></table>");
		var firstRow = "<tr class='cang'>";
		firstRow = firstRow + "<td class='first' colspan='" + (cwmx.points[0].length + 1) + "'>"
			+ " 测温明细" + " &nbsp;&nbsp;&nbsp;&nbsp;仓号：" + cwmx.storehousename
			+ "&nbsp;&nbsp;&nbsp;&nbsp;检测时间：" + cwmx.checktime + "</td>";
		firstRow = firstRow + "</tr>"
		$table.append($(firstRow));
		var points = cwmx.points;
		var alarmtemp = cwmx.alarmtemp;
		for (var i = 0; i < points.length; i++) {
			var alltemp = "0";
			var index = 0;
			for (var k = 0; k < points[i][0].length; k++) {
				if (k == 0) {
					var titleRow = "<tr class=\"hang\"><td>缆号</td>";
					for (var j = 0; j < points[i].length; j++) {
						if (points[i][j][k].lan == null) {
							titleRow = titleRow + "<td>" + "-" + "</td>";
						} else {
							titleRow = titleRow + "<td>" + points[i][j][k].lan + "号</td>";
						}
					}
					titleRow = titleRow + "</tr>";
					$table.append($(titleRow));
				}

				var dataRow = "<tr><td>" + (k + 1) + "层</td>"
				for (var j = 0; j < points[i].length; j++) {
					if (points[i][j][k].temp * 1 > alarmtemp) {
						dataRow = dataRow + "<td style=\"color:yellow;\">" + points[i][j][k].temp + "</td>";
					} else {
						if (points[i][j][k].temp * 1 == cwmx.highttemp * 1) {
							dataRow = dataRow + "<td style=\"color:red;font-weight:bold;\">" + points[i][j][k].temp + "</td>";
						} else if (points[i][j][k].temp * 1 == cwmx.lowertemp * 1) {
							dataRow = dataRow + "<td style=\"color:blue;font-weight:bold;\">" + points[i][j][k].temp + "</td>";
						} else {
							dataRow = dataRow + "<td>" + points[i][j][k].temp + "</td>";
						}
					}
					index = index + 1;
					alltemp = alltemp * 1 + points[i][j][k].temp * 1;
				}
				dataRow = dataRow + "</tr>";
				$table.append($(dataRow));
			}
		}
		var tr = "<tr>";
		tr = tr + "<td rowspan='5'>" + "统计" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "层号" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "最高温(℃)" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "最低温(℃)" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "平均温(℃)" + "</td>";
		$table.append($(tr));
		tr = "<tr>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "1层" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.onehigh + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.onelow + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.oneavg + "</td>";
		$table.append($(tr));
		tr = "<tr>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "2层" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.twohigh + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.twolow + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.twoavg + "</td>";
		$table.append($(tr));
		tr = "<tr>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "3层" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.threehigh + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.threelow + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.threeavg + "</td>";
		$table.append($(tr));
		tr = "<tr>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + "4层" + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.fourhigh + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.fourlow + "</td>";
		tr = tr + "<td colspan='" + (cwmx.points[0].length - 9) + "'>" + cwmx.fouravg + "</td>";
		$table.append($(tr));

		$("#cwmxView").append($table);
	}

	var printTable = function(cwmx) {
		if (cwmx.points == null) {
			return;
		}
		$("#printView").empty();
		var $table = $("<table class='dayinTable'></table>");
		var firstRow = "<tr class='cang'>";
		firstRow = firstRow + "</tr>";
		$table.append($(firstRow));
		var points = cwmx.points;
		var alarmtemp = cwmx.alarmtemp;
		var totalRow = cwmx.cabletier;
		for (var i = 0; i < points.length; i++) {
			var hightemp = "0";
			var lowtemp = "0";
			var alltemp = "0";
			var index = 0;
			for (var k = 0; k < points[i][0].length; k++) {
				if (k == 0) {
					var titleRow = "<tr class=\"hang\"><td class='line'>缆号</td>";
					for (var j = 0; j < points[i].length; j++) {
						if (points[i][j][k].lan == null) {
							titleRow = titleRow + "<td>" + "-" + "</td>";
						} else {
							titleRow = titleRow + "<td>" + points[i][j][k].lan + "号</td>";
						}
					}
					titleRow = titleRow + "</tr>";
					$table.append($(titleRow));
				}

				var dataRow = "<tr><td class=\"hang\">" + (k + 1) + "层</td>";

				if (totalRow == 3) {
					if (k == 0) {
						dataRow = "<tr><td>上层</td>";
					} else if (k == 1) {
						dataRow = "<tr><td>中层</td>";
					} else if (k == 2) {
						dataRow = "<tr><td>下层</td>";
					}
				} else if (totalRow == 4) {
					if (k == 0) {
						dataRow = "<tr><td>上层</td>";
					} else if (k == 1) {
						dataRow = "<tr><td>中上层</td>";
					} else if (k == 2) {
						dataRow = "<tr><td>中下层</td>";
					} else if (k == 3) {
						dataRow = "<tr><td>下层</td>";
					}
				} else if (totalRow == 5) {
					if (k == 0) {
						dataRow = "<tr><td>上层</td>";
					} else if (k == 1) {
						dataRow = "<tr><td>中上层</td>";
					} else if (k == 2) {
						dataRow = "<tr><td>中层</td>";
					} else if (k == 3) {
						dataRow = "<tr><td>中下层</td>";
					} else if (k == 4) {
						dataRow = "<tr><td>下层</td>";
					}
				}

				for (var j = 0; j < points[i].length; j++) {
					if (points[i][j][k].temp * 1 > alarmtemp) {
						dataRow = dataRow + "<td class=\"alarm\">" + points[i][j][k].temp + "</td>";
					} else {
						if(k == 0) {
							// 最高温标志
							if (points[i][j][k].temp * 1 == cwmx.onehigh * 1) {
								dataRow = dataRow + "<td class=\"high\">" + points[i][j][k].temp + "</td>";
							// 最低温标志
							} else if (points[i][j][k].temp * 1 == cwmx.onelow * 1) {
								dataRow = dataRow + "<td class=\"low\">" + points[i][j][k].temp + "</td>";
							} else {
								dataRow = dataRow + "<td>" + points[i][j][k].temp + "</td>";
							}
						} else if(k == 1) {
							// 最高温标志
							if (points[i][j][k].temp * 1 == cwmx.twohigh * 1) {
								dataRow = dataRow + "<td class=\"high\">" + points[i][j][k].temp + "</td>";
							// 最低温标志
							} else if (points[i][j][k].temp * 1 == cwmx.twolow * 1) {
								dataRow = dataRow + "<td class=\"low\">" + points[i][j][k].temp + "</td>";
							} else {
								dataRow = dataRow + "<td>" + points[i][j][k].temp + "</td>";
							}
						} else if(k == 2) {
							// 最高温标志
							if (points[i][j][k].temp * 1 == cwmx.threehigh * 1) {
								dataRow = dataRow + "<td class=\"high\">" + points[i][j][k].temp + "</td>";
							// 最低温标志
							} else if (points[i][j][k].temp * 1 == cwmx.threelow * 1) {
								dataRow = dataRow + "<td class=\"low\">" + points[i][j][k].temp + "</td>";
							} else {
								dataRow = dataRow + "<td>" + points[i][j][k].temp + "</td>";
							}
						} else if(k == 3) {
							// 最高温标志
							if (points[i][j][k].temp * 1 == cwmx.fourhigh * 1) {
								dataRow = dataRow + "<td class=\"high\">" + points[i][j][k].temp + "</td>";
							// 最低温标志
							} else if (points[i][j][k].temp * 1 == cwmx.fourlow * 1) {
								dataRow = dataRow + "<td class=\"low\">" + points[i][j][k].temp + "</td>";
							} else {
								dataRow = dataRow + "<td>" + points[i][j][k].temp + "</td>";
							}
						} else {
							dataRow = dataRow + "<td>" + points[i][j][k].temp + "</td>";
						}
						
					}
					if (points[i][j][k].temp * 1 > hightemp * 1 && points[i][j][k].temp * 1 != 1001) {
						hightemp = points[i][j][k].temp;
					}
					if (points[i][j][k].temp * 1 < lowtemp * 1 || lowtemp == 0) {
						lowtemp = points[i][j][k].temp;
					}
					index = index + 1;
					alltemp = alltemp * 1 + points[i][j][k].temp * 1;
				}
				dataRow = dataRow + "</tr>";
				$table.append($(dataRow));
			}
		}

		var $div = $("<div style='text-align:center'><font style='font-weight:900;font-size:25px;'>中央储备粮宿州直属库粮情报表<font></div>");
		$div.append($("<div style='text-align:left;font-size:18px;'>仓号：" + cwmx.storehousename
			+ "&nbsp;&nbsp;&nbsp;&nbsp;天气：" + cwmx.tainqi + "&nbsp;&nbsp;&nbsp;&nbsp;风向：" + cwmx.fengxiang
			+ "&nbsp;&nbsp;&nbsp;&nbsp;检测时间：" + cwmx.checktime + "  </div>"));
		$div.append($table);
		$table.append($("<tr><td colspan='" + (cwmx.points[0].length + 1)
			+ "' style='height:60px;text-align:left;border-top:1px solid #000;'>粮情分析：</td></tr>"));
		$table
			.append($("<tr><td colspan='"
				+ (cwmx.points[0].length + 1)
				+ "' style='text-align:center;'>"
				+ "组长：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
				+ "科长：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"));
		var $anaTable = $("<table class=\"cwmx\"></table>");
		$anaTable.append("<tr><td>仓温</td><td>" + cwmx.intemp + "</td><td>仓湿</td><td>" + cwmx.inhumidity
			+ "</td><td>气温</td><td>" + cwmx.outtemp + "</td><td>气湿</td><td>" + cwmx.outhumidity
			+ "</td><td>仓房类型</td><td>11</td></tr>");
		$anaTable.append("<tr><td>全仓平均</td><td>" + cwmx.avgtemp + "</td><td>中上层平均</td><td>" + cwmx.twoavg
			+ "</td><td>粮食品种</td><td>" + cwmx.grainpropertyname + "</td><td>设计容量t</td><td>" + cwmx.designcapacity
			+ "</td><td>实存数量t</td><td>" + cwmx.confirmcapacity + "</td></tr>");
		$anaTable.append("<tr><td>全仓最高</td><td>" + cwmx.highttemp + "</td><td>中上层最高</td><td>" + cwmx.twoavg
			+ "</td><td>发芽率</td><td></td><td>面筋持水率</td><td></td><td>入仓水分</td><td></td></tr>");
		$anaTable.append("<tr><td>全仓最低</td><td>" + cwmx.lowertemp + "</td><td>中上层最低</td><td>" + cwmx.twoavg
			+ "</td><td>容重/出糙</td><td></td><td>不完善率</td><td></td><td>当前水分</td><td></td></tr>");
		$anaTable.append("<tr><td>上层平均</td><td>" + cwmx.oneavg + "</td><td>中下层平均</td><td>" + cwmx.threeavg
			+ "</td><td>下层平均</td><td>" + cwmx.fouravg + "</td><td>杂质</td><td></td><td>产地</td><td></td></tr>");
		$anaTable.append("<tr><td>上层最高</td><td>" + cwmx.onehigh + "</td><td>中下层最高</td><td>" + cwmx.threehigh
			+ "</td><td>下层最高</td><td>" + cwmx.fourhigh + "</td><td>检测员</td><td>" + cwmx.checkername
			+ "</td><td>主管科长</td><td>" + cwmx.kezname + "</td></tr>");
		$anaTable.append("<tr><td>上层最低</td><td>" + cwmx.onelow + "</td><td>中下层最低</td><td>" + cwmx.threelow
			+ "</td><td>下层最低</td><td>" + cwmx.fourlow + "</td><td>保管员</td><td>" + cwmx.keepername
			+ "</td><td>主管主任</td><td>" + cwmx.mgrname + "</td></tr>");
		$div.append($anaTable);
		var $span = $("<div style='height:22px;padding-top:5px;text-align:left;font-size:12px;'><span style='padding-left:10px'>注：颜色深和方框是层温度最高点，颜色浅为层温度最低点</span><span style='padding-left:155px' id='dataTime'></span></div>");
		$div.append($span);
		$("#printView").append($div);
	}

	var getCwmx = function(storehousecode) {
		$.ajax({
			type : "GET",
			cache : false,
			url : "lq/XQlist?orgcode=" + orgcode + "&storehousecode=" + storehousecode,
			success : function(responseJson) {
				if (responseJson.success == true) { // 返回true
					cwmxBak = responseJson.obj;
					createTable(responseJson.obj);
					printTable(responseJson.obj);
					qiemian = responseJson.obj.pointList;
					drawQiemian(responseJson.obj.cablerow, responseJson.obj.cablecolum, responseJson.obj.cabletier,
						responseJson.obj.alarmtemp);

				} else {
					QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "error");
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				QTYYComponents.bootstrapSweetAlert("", "查询失败!!!", "error");
			}
		});
	}

	var getCwmxByid = function(id) {
		$.ajax({
			type : "GET",
			cache : false,
			url : "lq/XQlist?orgcode=" + orgcode + "&storehousecode=" + id,
			success : function(responseJson) {
				if (responseJson.success == true) { // 返回true
					cwmxBak = responseJson.obj;
					createTable(responseJson.obj);
					printTable(responseJson.obj);
					qiemian = responseJson.obj.pointList;
					drawQiemian(responseJson.obj.cablerow, responseJson.obj.cablecolum, responseJson.obj.cabletier,
						responseJson.obj.alarmtemp);

				} else {
					QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "error");
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				QTYYComponents.bootstrapSweetAlert("", "查询失败!!!", "error");
			}
		});
	}

	/**
	 * 绑定按钮事件
	 */
	var eventHandler = function() {
		$("#cwmxBtn").on("click", function() {
			$("#cwmxView").css("display", "block");
			$("#qiemianView").css("display", "none");
			$("#sanwenView").css("display", "none");
		});
		$("#qiemianBtn").on("click", function() {
			$("#cwmxView").css("display", "none");
			$("#qiemianView").css("display", "block");
			$("#sanwenView").css("display", "none");
		});
		$("#sanwenBtn").on("click", function() {
			$("#cwmxView").css("display", "none");
			$("#qiemianView").css("display", "none");
			$("#sanwenView").css("display", "block");
		});
		$("#printBtn").on("click", function() {
			var timer = $("#dataTime");
			var date = new Date();
			var seperator1 = "-";
			var seperator2 = ":";
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours()
			+ seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
			timer.html("制表时间：" + currentdate);
			
			$("#printView").css("display", "block");
			$("#printView").jqprint();
			$("#printView").css("display", "none");
		});
		$("#searchBtn").on("click", function() {
			getCwmx($("#cangfang").val());
			getSanwen($("#cangfang").val());
		});
	}

	return {
		init : function() {
			if ($("input[name=id]").val() != null && $("input[name=id]").val() != "") {
				$("#cangfangsearch").css("display", "none");
				$("#cangfangquery").css("display", "none");
			}
			QTYYComponents.initSelect("/dict/cangfang", "cangfang");
			eventHandler();
			if ($("input[name=id]").val() == null || $("input[name=id]").val() == "") {
				getSanwen($("#cangfang").val() == null ? "2" : $("#cangfang").val());
				getCwmx($("#cangfang").val() == null ? "2" : $("#cangfang").val());
				$("#exportBtn").attr(
					"href",
					"/excel?orgcode=" + orgcode + "&housecode="
					+ ($("#cangfang").val() == null ? "2" : $("#cangfang").val()));
			} else {
				getCwmxByid($("input[name=id]").val());
				getSanwen($("input[name=id]").val());
				$("#exportBtn").attr("href", "/excel?orgcode=" + orgcode + "&housecode=" + $("input[name=id]").val());
			/* $("#cangfangbianhao").text($("input[name=id]").val() + "号仓"); */
			}
		}
	}
}();

// 切面图相关
var changeX = function(X) {
	chart.xAxis[0].removePlotLine('plot-line-x');
	chart.yAxis[0].removePlotLine('plot-line-y');
	chart.zAxis[0].removePlotLine('plot-line-z');
	chart.xAxis[0].addPlotLine({ // 在x轴上增加
		value : X, // 在值为2的地方
		width : 2, // 标示线的宽度为2px
		color : 'red', // 标示线的颜色
		id : 'plot-line-x' // 标示线的id，在删除该标示线的时候需要该id标示
	});

	var newData = changeXData(X);
	chart.series[0].setData(newData);
}
var changeXData = function(X) {
	$("#qiemianTableView").empty();
	var wendu_data = [];
	var templow = "0";
	var temphigh = "";
	$.each(qiemian, function(n, value) {
		if (value.x == X) {
			if (templow == "0" || value.temp * 1 < templow * 1) {
				templow = value.temp;
			}
			if ((temphigh == "0" || value.temp * 1 > temphigh * 1) && value.temp * 1 != 1001) {
				temphigh = value.temp;
			}
		}
	});
	$.each(qiemian, function(n, value) {
		if (value.x == X) {
			var obj = new Object();
			obj.x = value.x * 1;
			obj.y = value.y * 1;
			obj.z = value.z * 1;
			obj.lan = value.lan;
			obj.temp = value.temp;
			if (obj.temp * 1 > alarm * 1) {
				obj.color = "yellow";
			} else {
				obj.color = "#87CEEB";
			}
			if (obj.temp * 1 == temphigh) {
				obj.color = "red";
			}
			if (obj.temp * 1 == templow) {
				obj.color = "blue";
			}
			wendu_data.push(obj);
		}
	});
	return wendu_data;
}
var changeY = function(Y) {
	chart.xAxis[0].removePlotLine('plot-line-x');
	chart.yAxis[0].removePlotLine('plot-line-y');
	chart.zAxis[0].removePlotLine('plot-line-z');
	chart.yAxis[0].addPlotLine({ // 在x轴上增加
		value : Y, // 在值为2的地方
		width : 2, // 标示线的宽度为2px
		color : 'blue', // 标示线的颜色
		id : 'plot-line-y' // 标示线的id，在删除该标示线的时候需要该id标示
	});
	var newData = changeYData(Y);
	chart.series[0].setData(newData);
}
var changeYData = function(Y) {
	$("#qiemianTableView").empty();
	var wendu_data = [];
	var templow = "0";
	var temphigh = "";
	$.each(qiemian, function(n, value) {
		if (value.y == Y) {
			if (templow == "0" || value.temp * 1 < templow * 1) {
				templow = value.temp;
			}
			if ((temphigh == "0" || value.temp * 1 > temphigh * 1) && (value.temp * 1 != 1001)) {
				temphigh = value.temp;
			}
		}
	});
	$.each(qiemian, function(n, value) {
		if (value.y == Y) {
			var obj = new Object();
			obj.x = value.x * 1;
			obj.y = value.y * 1;
			obj.z = value.z * 1;
			obj.lan = value.lan;
			obj.temp = value.temp;
			if (obj.temp * 1 > alarm * 1) {
				obj.color = "yellow";
			} else {
				obj.color = "#87CEEB";
			}
			if (obj.temp * 1 == temphigh) {
				obj.color = "red";
			}
			if (obj.temp * 1 == templow) {
				obj.color = "blue";
			}
			wendu_data.push(obj);
		}
	});

	if (cwmxBak.points == null) {
		return;
	}
	var $table = $("<table class='cwmx'></table>");
	var points = cwmxBak.points;
	var alarmtemp = cwmxBak.alarmtemp;
	for (var i = 0; i < points.length; i++) {
		var hightemp = "0";
		var lowtemp = "0";
		var alltemp = "0";
		var index = 0;
		for (var k = 0; k < points[i][0].length; k++) {
			if (k == 0) {
				var titleRow = "<tr class=\"hang\"><td>缆号</td>";
				for (var j = 0; j < points[i].length; j++) {
					if (points[i][j][k].lan == null) {
						titleRow = titleRow + "<td>" + "-" + "</td>";
					} else {
						titleRow = titleRow + "<td>" + points[i][j][k].lan + "号</td>";
					}
				}
				titleRow = titleRow + "</tr>";
				$table.append($(titleRow));
			}
			if (k == (Y * 1 - 1)) {
				var dataRow = "<tr><td>" + (k + 1) + "层</td>"
				for (var j = 0; j < points[i].length; j++) {
					if (points[i][j][k].temp * 1 > alarmtemp) {
						dataRow = dataRow + "<td style=\"color:red;\">" + points[i][j][k].temp + "</td>";
					} else {
						if (templow == points[i][j][k].temp) {
							dataRow = dataRow + "<td style='color:blue;font-weight:bold;'>" + points[i][j][k].temp + "</td>";
						} else if (temphigh == points[i][j][k].temp) {
							dataRow = dataRow + "<td style='color:red;font-weight:bold;'>" + points[i][j][k].temp + "</td>";
						} else {
							dataRow = dataRow + "<td>" + points[i][j][k].temp + "</td>";
						}
					}
					if (points[i][j][k].temp * 1 > hightemp * 1 && points[i][j][k].temp * 1 != 1001) {
						hightemp = points[i][j][k].temp;
					}
					if (points[i][j][k].temp * 1 < lowtemp * 1 || lowtemp == 0) {
						lowtemp = points[i][j][k].temp;
					}
					index = index + 1;
					alltemp = alltemp * 1 + points[i][j][k].temp * 1;
				}
				dataRow = dataRow + "</tr>";
				$table.append($(dataRow));
			}
		}
	}
	var tr = "";
	if (Y == 1) {
		tr = "<tr>";
		tr = tr + "<td rowspan='4'>" + "统计" + "</td>";
		tr = tr + "<td class='cwen' colspan='" + (cwmxBak.points[0].length + 1) + "'>" + "1层最高温：" + cwmxBak.onehigh
			+ " ；1层最低温：" + cwmxBak.onelow + " ；1层平均温：" + cwmxBak.oneavg + "</td>";
		$table.append($(tr));
	}
	if (Y == 2) {
		tr = "<tr>";
		tr = tr + "<td class='cwen' colspan='" + (cwmxBak.points[0].length + 1) + "'>" + "2层最高温：" + cwmxBak.twohigh
			+ " ；2层最低温：" + cwmxBak.twolow + " ；2层平均温：" + cwmxBak.twoavg + "</td>";
		$table.append($(tr));
	}
	if (Y == 3) {
		tr = "<tr>";
		tr = tr + "<td class='cwen' colspan='" + (cwmxBak.points[0].length + 1) + "'>" + "3层最高温：" + cwmxBak.threehigh
			+ " ；3层最低温：" + cwmxBak.threelow + " ；3层平均温：" + cwmxBak.threeavg + "</td>";
		$table.append($(tr));
	}
	if (Y == 4) {
		tr = "<tr>";
		tr = tr + "<td class='cwen' colspan='" + (cwmxBak.points[0].length + 1) + "'>" + "4层最高温：" + cwmxBak.fourhigh
			+ " ；4层最低温：" + cwmxBak.fourlow + " ；4层平均温：" + cwmxBak.fouravg + "</td>";
		$table.append($(tr));
	}
	$("#qiemianTableView").append($table);
	return wendu_data;
}

var changeZ = function(Z) {
	chart.xAxis[0].removePlotLine('plot-line-x');
	chart.yAxis[0].removePlotLine('plot-line-y');
	chart.zAxis[0].removePlotLine('plot-line-z');
	chart.zAxis[0].addPlotLine({ // 在x轴上增加
		value : Z, // 在值为2的地方
		width : 2, // 标示线的宽度为2px
		color : 'green', // 标示线的颜色
		id : 'plot-line-z' // 标示线的id，在删除该标示线的时候需要该id标示
	});
	var newData = changeZData(Z);
	chart.series[0].setData(newData);
}
var changeZData = function(Z) {
	$("#qiemianTableView").empty();
	var wendu_data = [];
	var templow = "0";
	var temphigh = "";
	$.each(qiemian, function(n, value) {
		if (value.z == Z) {
			if (templow == "0" || value.temp * 1 < templow * 1) {
				templow = value.temp;
			}
			if ((temphigh == "0" || value.temp * 1 > temphigh * 1) && (value.temp * 1 != 1001)) {
				temphigh = value.temp;
			}
		}
	});
	$.each(qiemian, function(n, value) {
		if (value.z == Z) {
			var obj = new Object();
			obj.x = value.x * 1;
			obj.y = value.y * 1;
			obj.z = value.z * 1;
			obj.lan = value.lan;
			obj.temp = value.temp;
			if (obj.temp * 1 > alarm * 1) {
				obj.color = "yellow";
			} else {
				obj.color = "#87CEEB";
			}
			if (obj.temp * 1 == temphigh) {
				obj.color = "red";
			}
			if (obj.temp * 1 == templow) {
				obj.color = "blue";
			}
			wendu_data.push(obj);
		}
	});
	return wendu_data;
}

jQuery(document).ready(function() {
	Sjxq.init();
});